<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fnx" uri="http://java.sun.com/jsp/jstl/functionsx" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="f" uri="http://www.sctv.com/tags/form" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="/WEB-INF/views/head.jsp"/>
    <script type="text/javascript">
        $(function () {
            $("#validForm").validate({
                submitHandler: function (form) {
                    $("#validForm input[name|='dy']").each(function () {
                        var name = $(this).attr("name");
                        $(this).attr("name", name.substring(3, name.lastIndexOf("-")));
                    });
                    form.submit();
                }
            });
            $("input[name='name']").focus();

            //相关新闻显示篇数
            function getJsonLength(jsonData){
                var jsonLength = 0;
                for(var item in jsonData){
                    jsonLength++;
                }
                return jsonLength;

            }
            var relateJsonStr='${bean.relateNews}';
            var count=0
            if(relateJsonStr!="" && relateJsonStr!=null){
                var relateNewJson=JSON.parse('${bean.relateNews}');
                count=getJsonLength(relateNewJson);
            }
            $("#relatednewsIdName").val(count+"篇");
        });

        function confirmDelete() {
            return confirm("<s:message code='confirmDelete'/>");
        }

        function optMulti(form, action, msg) {
            if (Cms.checkeds("ids") == 0) {
                alert("<s:message code='pleaseSelectRecord'/>");
                return false;
            }
            if (msg && !confirm(msg)) {
                return false;
            }
            form.action = action;
            form.submit();
            return true;
        }

        function liveSave(form, action, msg) {
            if (msg && !confirm(msg)) {
                return false;
            }
            form.action = action;
            form.submit();
            return true;
        }
    </script>
</head>
<body class="skin-blue content-body">
<jsp:include page="/WEB-INF/views/commons/show_message.jsp"/>
<div class="content-header">
    <h1>启动页 - <s:message code="${oprt=='edit' ? 'edit' : 'create'}"/></h1>
</div>
<c:set var="numberExist"><s:message code="vote.number.exist"/></c:set>
<div class="content">
    <div class="box box-primary">
        <form class="form-horizontal" id="validForm" action="${oprt=='edit' ? 'update' : 'save'}.do" method="post">
            <tags:search_params/>
            <f:hidden name="id" value="${bean.id}"/>
            <f:hidden name="position" value="${position}"/>
            <input type="hidden" id="redirectLive" name="redirect" value="edit"/>
            <div class="box-header with-border">
                <div class="btn-toolbar">
                    <div class="btn-group">
                        <shiro:hasPermission name="ext:vote:create">
                            <button class="btn btn-default" type="button"
                                    onclick="location.href='create.do?stat=${stat}';"<c:if
                                    test="${oprt=='create'}"> disabled="disabled"</c:if>><s:message
                                    code="create"/></button>
                        </shiro:hasPermission>
                    </div>
                    <div class="btn-group">
                        <shiro:hasPermission name="ext:vote:delete">
                            <button class="btn btn-default" type="button"
                                    onclick="if(confirmDelete()){location.href='delete.do?ids=${bean.id}';}"
                                    <c:if test="${oprt=='create'}"> disabled="disabled"</c:if>><s:message
                                    code="delete"/></button>
                        </shiro:hasPermission>
                    </div>

                    <div class="btn-group">
                        <button class="btn btn-default" type="button"
                                onclick="location.href='list.do';"><s:message
                                code="return"/></button>
                    </div>
                </div>
            </div>
            <div class="box-body">
                <div class="row">
                    <div class="col-sm-8">
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><em class="required">*</em>名称</label>
                            <div class="col-sm-10">
                                <f:text name="name" value="${bean.name}"
                                        class="form-control required" maxlength="150"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-8">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序值: </label>
                            <div class="col-sm-10">
                                <f:text name="sort" value="${bean.sort}"
                                        class="form-control {maxlength:255}" rows="5"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-8">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">时间： </label>
                            <div class="col-sm-8">
                                <div class="col-sm-4">
                                    <input type="text" name="startTime"
                                           value="<fmt:formatDate value="${bean.startTime}" pattern="yyyy-MM-dd'T'HH:mm:ss"/>"
                                           onclick="WdatePicker({dateFmt:'yyyy-MM-ddTHH:mm:ss'});" class="form-control"
                                           style="padding-left:3px;padding-right:3px;"/>
                                </div>
                                <div class="col-sm-1">
                                至
                                </div>
                                    <div class="col-sm-5">
                                         <input type="text" name="endTime"
                                               value="<fmt:formatDate value="${bean.endTime}" pattern="yyyy-MM-dd'T'HH:mm:ss"/>"
                                               onclick="WdatePicker({dateFmt:'yyyy-MM-ddTHH:mm:ss'});" class="form-control"
                                               style="padding-left:3px;padding-right:3px;"/>
                                    </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>


            <div class="row">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">广告启动图</label>
                            <div class="col-sm-10">
                                <script>
                                    function fn_smallImage(src) {
                                        Cms.scaleImg("img_smallImage", 200, 100, src);
                                    };
                                </script>
                                <div style="display:table;width:100%;">
                                    <div style="display:table-cell;vertical-align:middle;">
                                        <div class="input-group">
                                            <span class="input-group-addon">地址</span>
                                            <input type="text" id="smallImage" name="pictureUrl"
                                                   value="${bean.pictureUrl}"
                                                   onchange="fn_smallImage(this.value);" class="form-control ">
                                        </div>
                                        <div class="form-inline" style="margin-top:3px;">
                                            <button class="btn btn-default" type="button" id="smallImageButton">选择
                                            </button>
                                            <object id="SWFUpload_0" type="application/x-shockwave-flash"
                                                    data="/static/vendor/swfupload/swfupload.swf?preventswfcaching=1502702265304"
                                                    width="54" height="34" class="swfupload">
                                                <param name="wmode" value="transparent">
                                                <param name="movie"
                                                       value="/static/vendor/swfupload/swfupload.swf?preventswfcaching=1502702265304">
                                                <param name="quality" value="high">
                                                <param name="allowScriptAccess" value="always">
                                                <param name="flashvars"
                                                       value="movieName=SWFUpload_0&amp;uploadURL=%2Fcmscp%2Fcore%2Fupload_image.do%3Bjsessionid%3DB7EED2164EABD024D9BFE3361803971D%3F_site%3D&amp;useQueryString=false&amp;requeueOnError=false&amp;httpSuccess=&amp;assumeSuccessTimeout=0&amp;params=&amp;filePostName=file&amp;fileTypes=*.*&amp;fileTypesDescription=Images&amp;fileSizeLimit=0&amp;fileUploadLimit=0&amp;fileQueueLimit=0&amp;debugEnabled=false&amp;buttonImageURL=&amp;buttonWidth=54&amp;buttonHeight=34&amp;buttonText=&amp;buttonTextTopPadding=0&amp;buttonTextLeftPadding=0&amp;buttonTextStyle=color%3A%20%23000000%3B%20font-size%3A%2016pt%3B&amp;buttonAction=-100&amp;buttonDisabled=false&amp;buttonCursor=-2">
                                            </object>
                                            <button class="btn btn-default" type="button">上传</button>
                                            <div style="display: none">
                                                <button class="btn btn-default" type="button" id="smallImageSwfCancel"
                                                        onclick="smallImageSwfUpload.cancelQueue();" disabled="">取消
                                                </button>
                                            </div>

                                        </div>

                                        <input type="hidden" id="t_smallImage" value="false">
                                        <input type="hidden" id="tw_smallImage" value="116">
                                        <input type="hidden" id="th_smallImage" value="77">
                                    </div>
                                    <div style="width:200px;display:table-cell;vertical-align:middle;text-align:center;">
                                        <img id="img_smallImage" style="display:none;">
                                    </div>
                                </div>
                                <div id="smallImageSwfProgress"></div>
                                <script>
                                    var smallImageSwfUpload = Cms.swfUploadImage("smallImage", {
                                        jsessionid: "B7EED2164EABD024D9BFE3361803971D",
                                        file_size_limit: "0",
                                        file_types: "*.*"
                                    });
                                    $(function () {
                                        Cms.f7.uploads("smallImage", "smallImage", {
                                            settings: {"title": "选择附件"},
                                            callbacks: {
                                                "ok": function (src) {
                                                    fn_smallImage(src);
                                                }
                                            }
                                        });
                                    });
                                </script>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><em class="required"></em>启动时间[s]</label>
                        <div class="col-sm-10">
                            <f:text name="modifyTime" value="${(bean.modifyTime)}"  class="form-control" maxlength="10"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><em class="required"></em>是否启动</label>
                        <div class="col-sm-10">
                            <select class="form-control" name="isStart">
                                <f:option value="0" selected="${bean.isStart}">关闭</f:option>
                                <f:option value="1" selected="${bean.isStart}">开启</f:option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <%------------------------------------相关新闻 start------------------------------------%>
            <div class="row" style="margin-top: 10px;margin-bottom: 10px;">
                <label class="col-sm-2 control-label">相关新闻</label>
                <div class="col-sm-4">
                    <div class="input-group">
                        <f:text  id="relatednewsIdName" class="form-control" value="${bean.relateNews}" disabled="true"/>
                        <f:hidden id="relatednewsId" name="relateNews" value="${bean.relateNews}"/>
                        <span class="input-group-btn">
							   		<button class="btn btn-default" id="relatednewsIdButton" type="button">选择</button>
							    </span>
                    </div>

                </div>

            </div>
            <script type="text/javascript">
                $(function(){

                    $(function() {
                        Cms.f7.chooseRelatednews("relatednewsId","relatednewsIdName",'${bean.id}',{
                            settings: {"title": "选择相关新闻"}
                        });
                    });
                });
            </script>
            <%-------------------------------------相关新闻 end--------------------------------------%>

            <%-----------------------------------------------------------[  按钮 保存 如下:  ]----------------------------------------------------------------------------------%>
            <div class="box-footer">
                <button class="btn btn-primary" type="submit" onclick="$('#redirectLive').val('edit');"><s:message
                        code="save"/></button>
                <button class="btn btn-default" type="submit" onclick="$('#redirectLive').val('list');"><s:message
                        code="saveAndReturn"/></button>
                <c:if test="${oprt=='create'}">
                    <button class="btn btn-default" type="submit" onclick="$('#redirectLive').val('create');"><s:message
                            code="saveAndCreate"/></button>
                </c:if>
            </div>
        </form>
    </div>
</div>
</div>
</body>
</html>